package com.example.hcbmsm.service.impl;

import com.auth0.jwt.interfaces.Claim;
import com.example.hcbmsm.domain.Admin;
import com.example.hcbmsm.mapper.AdminMapper;
import com.example.hcbmsm.service.AdminService;
import com.example.hcbmsm.util.HCBMSMResult;
import com.example.hcbmsm.util.JavaWebToken;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Map;

/**
 * @author Xinghm
 * @version 1.0
 * @since 2024/11/5 17:25
 */
@Service
public class AdminServiceImpl implements AdminService {
    @Autowired
    private AdminMapper adminMapper;

    @Override
    public Map getUser(String token) {
        Map<String, Claim> tokenInfo = JavaWebToken.getTokenInfo(token);
        Long adminId = new Long(tokenInfo.get("adminId").asString());
        Admin admin = adminMapper.selectByPrimaryKey(adminId);
        admin.setAdminPassword("");
        return HCBMSMResult.SUCCESS(admin);
    }
}
